﻿using System;
using System.Collections.Generic;
using System.Text;
using OVS.CoreDomain.Data;
using OVS.CoreDomain;
using System.Data;

namespace OVS.Data
{
    public class DalPanchayat : Dal<IPanchayat, Panchayat>, IDalPanchayat
    {

        private const string SP_GET_PANCHAYATS = "usp_GetPanchayats";

        private readonly IDalManager _manager;
        private static readonly IDalPanchayat _instance = new DalPanchayat();

        public static IDalPanchayat Instance
        {
            get { return _instance; }
        }

        public DalPanchayat()
        {
            _manager = new DalManager();
        }

        public DalPanchayat(IDalManager manager)
        {
            _manager = manager;
        }

        protected override void Convert(IPanchayat obj, DataRow row)
        {
            obj.DistrictId = _manager.GetValue<string>(row, "DistrictId");
            obj.PanchayatId = _manager.GetValue<string>(row, "PanchayatId");
            obj.PanchayatName  = _manager.GetValue<string>(row, "PanchayatName");
            
        }

        public IList<IPanchayat> GetPanchayats(string districtId)
        {
            _manager.StoredProcedureName = SP_GET_PANCHAYATS;
            _manager.AddInParameter("@DistrictId", DbType.String, districtId);

            List<IPanchayat> panchayats = new List<IPanchayat>();
            foreach (IPanchayat panchayat in ConvertAll(_manager.ExecuteDataSet()))
                panchayats.Add(panchayat);



            return panchayats;



        }
    }
}
